import { CheckboxValueType } from "ant-design-vue/es/checkbox/interface";
import { Rect, Line, Polygon } from "@/global-utils/fabric";
import { UnwrapNestedRefs } from "vue";
// a-select组件的options
export declare type TsSelectOptItem = {
  // 搜索条件的名称
  label: string;
  // 搜索条件的值定义
  value: any;
};

// 账号管理弹窗类型
export type DataAuthType = "camera" | "alarm";
export type TsAccountModalType =
  | "addEdit"
  | "password"
  | "transfer"
  | "cameraDataAuth"
  | "alarmDataAuth";

// 新增&编辑账户的表单参数定义
export type TsAccountForm = {
  id?: string | number;
  userName: string;
  phone: string;
  roleId: string | number | undefined;
  password?: string;
  confirmPassword?: string;
};

// 重置密码的表单参数定义
export type TsResetPwdForm = {
  id: string | number;
  password: string;
  confirmPassword: string;
};

// 转移超管账号的表单参数定义
export type TsTransferForm = {
  oldSuperAdminId: string | number; // 原超管账号ID
  oldSuperNewRoleId: string | number | undefined; // 原超管账号新角色ID
  newSuperAdminId: string | number | undefined; // 新超管账号ID
  changeSuperFlag: number; // 判断是否是超管账号转移的标识：0 不是，1 是
};

// 角色表单的参数定义
export type TsRoleForm = {
  id?: string | number;
  roleName: string; // 角色名称
  menuIds: (string | number)[]; // 菜单和按钮的id集合
};

/**
 * ------------- 盒子版本
 */
// 版本上传表单的参数定义
export type TsVersionForm = {
  upPackageName: string; // 升级包名称
  version: string; // 版本
  type: number | string; // 类型
  multipartFile: string; // 升级包
  versionDescription: string; // 升级包描述
  address: string;
};

// 版本上传升级包参数定义
export type TsFile = {
  name?: string;
  status?: string;
};

/**
 * ------------- 盒子管理
 */
// 卡片页信息
export declare type TsCardInfo = {
  boxName: string;
  id?: string | number;
  serial: string;
  totalDeviceCount: string;
  status: string | number;
  visible: boolean;
};

// 基本信息
export declare type _TsBasicInfo = {
  boxName: string;
  systemTime: string;
  serial: string;
  firmwareVersion: string;
  softwareVersion: string;
  totalDeviceCount: string;
  os: string;
  model: string;
  cpu: string;
  memory: string;
  disk: string;
  sdkVersion: string;
};

// rowkeys类型
export declare type Key = string | number;

/**
 * AI配置表单
 */
export declare type ServiceForm = {
  id?: number;
  aiSrvId?: number;
  aiSrvStatus?: number;
  aiSrvTriggerInterval: number;
  aiSrvDelayTriggerSeconds: number;
  aiSrvAlgorithmSensitivity: number;
  alertImageType: number;
  avAlarmStatus: number;
  validCycleTime: any[];
  aiSrvExtraArgs: any;
  aiSrvAlarmName: string;
  intervalMin?: number;
  intervalMax?: number;
  delayMin?: number;
  delayMax?: number;
};
// 文件列表
export interface FileList {
  id?: number;
  name?: string;
  status?: "done" | "loading" | "error" | "removed";
  url?: string;
  originalUrl?: string;
  disabled?: boolean;
}
// // a-select组件的options
// export declare type TsSelectOptItem = {
// 	// 搜索条件的名称
// 	label: string;
// 	// 搜索条件的值定义
// 	value: any;
// };

// 报警通知表单
export declare type _TsformDatanfo = {
  name: string;
  type: number;
  aiIdList?: any[];
  alarmTypeList?: CheckboxValueType[];
  notifyTypeList: CheckboxValueType[];
  deviceIdList: any;
  notifyPersonList: [{ userName: string; phone: string; id?: string | number }];
};
export namespace TsG6UseRoleForm {
  /* ----------------------------------- 参数/属性 ----------------------------------- */

  // 按钮的定义
  export type ButtonItem = any & {
    id: string | number;

    // 相同菜单的其他按钮保存一下“页面浏览”按钮的id
    displayBtnId: string | number;

    [propKey: string]: any;
  };

  // 菜单目录的定义
  export type MenuItem = any & {
    id: string | number;

    // 是否勾选, 后端默认返回 false 值, 基本由前端自己处理
    checkEd: boolean;

    // 重新定义 button 的类型, 增加了本 hooks 补充的定义
    pageBtnList: ButtonItem[];

    // 重新定义 child 的类型, 增加了本 hooks 补充的定义
    childList: MenuItem[];

    // 收集自身按钮和自身子级页面的按钮id
    tempAllBtnIds: (string | number)[];

    [propKey: string]: any;
  };
  // 菜单定义
  export type menuType =
    | "default-page"
    | "displayPage"
    | "drilldown-page"
    | "directory";

  // 当前选中的菜单项 key 数组
  export type SelectedKeys = (string | number)[];

  // 当前展开的 SubMenu(目录)菜单项 key 数组
  export type OpenKeys = (string | number)[];

  // 菜单页面关于权限操作的数据定义
  export interface MenusAttr {
    selectedKeys: SelectedKeys;
    openKeys: OpenKeys;
    menus: MenuItem[];
    flatMenus: {
      [propKey: string | number]: MenuItem;
    };
    checkedMenuIds: (string | number)[];
    checkedBtnIds: (string | number)[];
  }

  // 遍历数据源查询指定项数据的回调函数
  export type FindItemCallback = (data: MenuItem) => void;

  //所有菜单id
  export type AllMenuIds = (string | number)[];
  //所有按钮id
  export type AllBtnIds = (string | number)[];

  type PageBtnList = {
    id: string | number;
    title: string;
    ext: { remark: string };
  };
  type SelectedMenuItem = {
    id: string | number;
    title: string;
    pageBtnList: PageBtnList[];
    childList: SelectedMenuItem[];
  };
  // menusConf.selectedKeys 获取当前点击选中的 菜单项  返回：当前点击选中的 菜单项
  export type CSelectedMenu = ComputedRef<SelectedMenuItem>;

  //判断是否存在下级菜单 显示半选和 其余项正常选中状态 返回: 当前点击选中的 菜单项
  export type CSelected = ComputedRef<
    (btnItem: any, isChecked: boolean) => boolean | undefined
  >;
  //根据当前已选择的菜单, 判断 全选和 半选 的状态, 返回 checked = 全选, indeterminate = 半选
  export type CMenuCheckBoxState = ComputedRef<{
    checked: boolean;
    indeterminate: boolean;
  }>;
  //是否禁用 “全选” 按钮
  export type CDisableAllCheck = ComputedRef<boolean>;
  //菜单目录和按钮进行勾选操作后, 统计勾选的数量, 需要传参为 菜单的 code值  返回: 字符串值 = 已勾选按钮的数量 / 所有按钮数量
  export type CBtnSelectedNums = ComputedRef<(id: string | number) => string>;
  // 单个按钮的禁用状态判断
  export type CDisabledBtnCheck = ComputedRef<
    (
      btn: TsG6UseRoleForm.ButtonItem,
      menuType: TsG6UseRoleForm.menuType
    ) => boolean | undefined
  >;
  //默认选中第一个菜单页面 参数1: data = 菜单目录数组中的第一项数据
  export type SetFirstMenu = (data: TsG6UseRoleForm.MenuItem) => void;
  //Menu 组件切换选择 参数1: itemId = 点击的menu节点的id
  export type SetMenuItemClick = (itemId: string | number) => void;
  // 格式化后端接口返回的菜单数据, 并赋值给 menuAttr.menus 和 menuAttr.flatMenus, 并且默认选中第一个菜单 参数1: resMenus = 要格式化的菜单数据(数组)
  export type SetFormatMenus = (resDatas: TsG6UseRoleForm.MenuItem[]) => void;

  //根据后端接口返回的已选择id, 更新 menuAttr.checkedMenuIds 和 menuAttr.checkedBtnIds 参数1: selectedIds 后端接口返回的已选id集合
  export type SetSelectedIds = (selectedIds: (string | number)[]) => void;

  //全选 或者 取消全选 的功能 @param check = 全选？取消全选
  export type SetCheckAllMenus = (check: boolean) => void;
  //已选择菜单目录的整体勾选 参数: check = 是否勾选
  export type SetMenuItemCheck = (check: boolean) => void;
  //单个按钮的勾选操作   参数1: check = 是否勾选 参数2: btn = 当前操作的按钮
  export type SetButtonItemCheck = (
    check: boolean,
    btn: TsG6UseRoleForm.ButtonItem
  ) => void;
  // hook返回
  export type HooksReturns = {
    menuAttr: TsG6UseRoleForm.MenusAttr;
    cSelectedMenu: TsG6UseRoleForm.CSelectedMenu;
    cSelected: TsG6UseRoleForm.CSelected;
    cMenuCheckBoxState: TsG6UseRoleForm.CMenuCheckBoxState;
    cDisableAllCheck: TsG6UseRoleForm.CDisableAllCheck;
    cBtnSelectedNums: TsG6UseRoleForm.CBtnSelectedNums;
    cDisabledBtnCheck: TsG6UseRoleForm.CDisabledBtnCheck;
    setMenuItemClick: TsG6UseRoleForm.SetMenuItemClick;
    setFormatMenus: TsG6UseRoleForm.SetFormatMenus;
    setSelectedIds: TsG6UseRoleForm.SetSelectedIds;
    setCheckAllMenus: TsG6UseRoleForm.SetCheckAllMenus;
    setMenuItemCheck: TsG6UseRoleForm.SetMenuItemCheck;
    setButtonItemCheck: TsG6UseRoleForm.SetButtonItemCheck;
  };
}

//=============== ai算法服务表单========================

//服务列表 项
// export interface AiServiceListItem {
// 	aiSrvDrawType: number;
// 	aiSrvId: number;
// 	aiSrvName: string;
// 	aiSrvStatus: number;
// 	createTime: number | string;
// 	id: number;
// 	num: number;
// 	selected: number;
// }
export interface AiServiceListItem {
  id: number;
  boxSerial: string;
  aiSrvName: string;
  aiSrvType: number;
  useDefaultConfig: number;
  selected: number;
  aiSrvDrawType: number;
  selectable: number;
  effective: number;
  serviceName: string;
  deviceAISrvCustomizeConfig?: AiServiceListItem | null;
}

//算法配置tab
export interface ConfigList {
  areaId: number;
  boxSerial: string;
  customizeDrawAreaCoordinates: number[][] | null;
  deviceAreaAIId: number;
  deviceId: number;
  id: number;
  sort: number;
}

// 视频顶部操作
export type TopControlsState = {
  serviceModalVisible: boolean; // 配置表单弹窗显隐
  copyAllRegionVisible: boolean; // 复制到区域的弹窗显隐
};

// 区域字段
export type AreaState = {
  areaInfo: { [attr: string]: any };
  areaId: undefined | number;
  areaList: any;
  areaAiNum: number;
};
// 算法服务列表字段
export type ServeState = {
  serviceId: number | null;
  serviceList: AiServiceListItem[];
  serviceName: string;
  serviceType: number;
};

// 页面操作控制字段
export type PageControlState = {
  switchCheckedDisabled: boolean;
  isLoadVideoSuccess: boolean;
  saveBtnLoading: boolean;
  videoDrawSwitch: boolean | -1;
  OfflineStatus: boolean;
  isCavansShow: boolean;
  hasAlgoAuth: boolean;
  isEdit: boolean;
};

// 摄像头信息
export interface CameraInfoState {
  boxSerial: string;
  id: number | string;
  cameraId: number | string;
  status: number | string;
  name: string;
  url: string;
  deviceTreeKey: string;
  aiSrvCountV2: number;
}

enum DrawType {
  Rect = 1, //矩形
  Line = 2, //线
  Polygon = 3, //多边形
}

// =========================hooks 类型===============================
export type UseCanvasDraw = () => UseCanvasDrawReturn;
// 绘制标注 类型
export type CanvasState = {
  canvas: fabric.Canvas | null;
  video: HTMLVideoElement | null;
  rect: Rect | null;
  line: Line | null;
  polygon: Polygon | null;
  backgroundVideo: fabric.Image | null;
  scale: number;
  isClearnCanvas: boolean;
  isClearnOk: boolean;
  drawType: DrawType;
  isEditCavans: boolean;
  selectGraph: any;
};

export type UseCanvasDrawReturn = {
  initCanvas: () => Promise<void>;
  drawVideo: () => void;
  handleClearCanvas: () => void;
  drawDefaultArea: (axisList: [number, number][][]) => void;
  clearCanvas: () => Promise<void>;
  fullRect: () => void;
  stopDraw: () => void;
  drawLine: () => void;
  drawPolygon: () => void;
  destroy: () => Promise<void>;
  getCoordinateValue: () => number[][];
  delGraph: () => void;
  canvasState: UnwrapNestedRefs<CanvasState>;
};
